package com.wb.web.controller.videos;

import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.vo.DeleteRequest;
import com.wb.common.vo.MaterialsModelVO;
import com.wb.common.vo.VideosModelVO;
import com.wb.system.domain.MaterialsEntity;
import com.wb.system.domain.VideosEntity;
import com.wb.system.service.MaterialsService;
import com.wb.system.service.VideosService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 视频课程
 */
@RestController
@RequestMapping("videos")
@Api(tags = "视频课程")
public class VideosController extends BaseController {
    @Autowired
    private VideosService videosService;

    @PostMapping("/list")
    @ApiOperation("视频课程列表")
    public TableDataInfo list(@RequestBody VideosModelVO videosModelVO) {
        startPage();
        List<VideosEntity> list = videosService.selectVideosList(videosModelVO);
        return getDataTable(list);
    }

    @PostMapping("/{id}/like")
    @ApiOperation("点赞视频")
    public Object download(@PathVariable("id") String id) {
        return null;
    }

    @GetMapping("/{id}")
    @ApiOperation("获取视频详情")
    public AjaxResult get(@PathVariable("id") Long id) {
        return AjaxResult.success(videosService.selectById(id));
    }

    @PostMapping("/add")
    @ApiOperation("资料创建")
    public AjaxResult add(@Valid @RequestBody VideosEntity videosModelVO) {
        VideosEntity videosEntity = new VideosEntity();
        BeanUtils.copyProperties(videosModelVO, videosEntity);
        videosService.saveVideos(videosEntity);
        return AjaxResult.success();
    }


    @PostMapping("/update")
    @ApiOperation("更新职位")
    public AjaxResult update(@RequestBody VideosEntity videosModelVO) {
        VideosEntity videosEntity = new VideosEntity();
        BeanUtils.copyProperties(videosModelVO, videosEntity);
        videosEntity.setUpdateBy(getUsername());
        videosService.updateVideosById(videosEntity);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteAll")
    @ApiOperation("删除All")
    public AjaxResult deleteAll(@RequestBody DeleteRequest request) {
        videosService.removeVideosByIds(request.getIds());
        return AjaxResult.success();
    }
}
